package com.lkd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lkd.domain.Order;
import com.lkd.domain.TimeInterval;
import com.lkd.mapper.OrderMapper;
import com.lkd.service.IOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2025-02-12
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Override
    public Integer getOrderCount(TimeInterval interval) {
        LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<>();
        wrapper.le(Order::getCreateTime,interval.getEnd()).ge(Order::getCreateTime,interval.getStart());

        int count = count(wrapper);
        return count;
    }

    @Override
    public Long getOrderAmount(TimeInterval timeInterval) {
        LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<>();
        wrapper.le(Order::getCreateTime,timeInterval.getEnd()).ge(Order::getCreateTime,timeInterval.getStart());
        List<Order> orders = list(wrapper);
        Long amout = 0L;
        for (Order order : orders) {
            amout += order.getAmount();
        }
        return amout;
    }
}
